package com.zhiyou100.springbootweather.controller;

import com.zhiyou100.springbootweather.pojo.City;
import com.zhiyou100.springbootweather.service.ICityService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CityController {
    @Resource
    private ICityService cityService;



    /**
     * 查询所有的 省份返回json数据
     * @return
     */
    @RequestMapping(value = "citys", method = RequestMethod.POST)
    public List<City> citys() {
        List<City> pcdList = cityService.queryAllPZH();  //查询所有得 省份
        return pcdList;//发送到前端
    }

    /**
     * 根据省份 查询所有的市 返回
     * @param provinceZh
     * @return
     */
    @RequestMapping(value = "leas")
    public List<City> leas(String provinceZh) {
        List<City> pcdList = cityService.queryAllLZH(provinceZh); //查询所有得 市
        return pcdList;
    }

    /**
     * 根据 市名 查询所有的 区县
     * @param leaderZh
     * @return
     */
    @RequestMapping(value = "citZh")
    public List<City> citZh(String leaderZh,String pName) {

        List<City> pcdList = cityService.queryAllCZH(leaderZh,pName);//查询所有得区/县
        return pcdList;
    }
}
